package com.ruoyi.personnel.salary.hourly.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.personnel.salary.hourly.domain.HourlyCond;
import com.ruoyi.personnel.salary.hourly.domain.HourlyDomain;
import com.ruoyi.personnel.salary.hourly.domain.HourlyDto;
import com.ruoyi.personnel.salary.hourly.service.IHourlyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


import java.util.List;


/**
 * 计时工资
 * 视图层
 */
@RestController
@RequestMapping("/salary/hourly")
@Api(value = "计时工资信息模块", tags = "计时工资接口")
public class HourlyController extends BaseController {
    @Autowired
    private IHourlyService hourlyService;

    /**
     * 根据搜索条件所有计时工资记录
     * @param cond 搜索条件
     * @return
     */
    @ApiOperationSupport(includeParameters = {"HourlyCond.hourlyWageId", "HourlyCond.staffId", "HourlyCond.createTime"})
    @ApiOperation(value = "获取计时工资列表",notes = "查询所有计时工资信息")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody HourlyCond cond) {
        startPage();
        List<HourlyDto> hourlyList = hourlyService.selectHourlyList(cond);
        return getDataTable(hourlyList);
    }

    /**
     * 新增计时工资记录
     * @param hourly
     * @return
     */
    @ApiOperation(value = "新增计时工资记录", notes = "新增计时工资记录信息")
    @ApiImplicitParam(name = "hourly", value = "新增计时工资记录", dataType = "HourlyDomain")
    @PostMapping("/add")
    public AjaxResult add(@Validated @RequestBody HourlyDomain hourly) {
        return toAjax(hourlyService.insertHourly(hourly));
    }

    /**
     * 修改计时工资记录
     * @param hourly
     * @return
     */
    @ApiOperation(value = "修改计时工资记录", notes = "修改计时工资信息")
    @ApiImplicitParam(name = "hourly", value = "修改计时工资记录", dataType = "HourlyDomain")
    @PostMapping("/edit")
    public AjaxResult edit(@Validated @RequestBody HourlyDomain hourly) {
        return toAjax(hourlyService.updateHourly(hourly));
    }

    /**
     * 删除计时工资记录
     * 仅修改删除标志
     * @param hourly
     * @return
     */
    @ApiOperation(value = "删除计时工资记录", notes = "删除计时工资记录,仅删除标志位")
    @PostMapping("/delete")
    public AjaxResult delete(@RequestBody HourlyDomain hourly) {
        return toAjax(hourlyService.updateHourlyDeleteFlag(hourly));
    }

//    @ApiOperation(value = "读取计时工资", notes = "读取计时工资")
//    @GetMapping("/{staffId}")
//    public AjaxResult readMonthlySalary(@PathVariable String staffId) {
//        Map<String, Double> map = new HashMap<>();
//        Double hourlyWage = hourlyService.getHourlyWage(staffId);
//        map.put("hourlyWage", hourlyWage);
//        return AjaxResult.success("查询成功", map);
//    }
}
